<?php
// +----------------------------------------------------------------------
// | ThinkCMF [ WE CAN DO IT MORE SIMPLE ]
// +----------------------------------------------------------------------
// | Copyright (c) 2013-2017 http://www.thinkcmf.com All rights reserved.
// +----------------------------------------------------------------------
// | Author: Dean <zxxjjforever@163.com>
// +----------------------------------------------------------------------
namespace api\api\controller;


use api\api\service\IndexService;
use api\api\service\MyService;
//use Wechatdd;
use api\api\wechat\MiniAppUtil;
use api\api\service\OrderService;

use app\admin\model\RoleUserModel;
use app\admin\model\UserModel;
use app\common\util\TpshopException;
use cmf\controller\RestBaseController;
use think\Db;
use think\facade\Env;

class MyController extends RestBaseController
{
    public function adminlogin(){

        $name = $this->request->param("username");
        if (empty($name)) {
            $this->error(lang('USERNAME_OR_EMAIL_EMPTY'));
        }
        $pass = $this->request->param("password");
        if (empty($pass)) {
            $this->error(lang('PASSWORD_REQUIRED'));
        }
        if (strpos($name, "@") > 0) {//邮箱登陆
            $where['user_email'] = $name;
        } else {
            $where['user_login'] = $name;
        }

        $result = UserModel::where($where)->find();

        if (!empty($result) && $result['user_type'] == 1) {
            if (cmf_compare_password($pass, $result['user_pass'])) {
                $groups = RoleUserModel::alias("a")
                    ->join('role b', 'a.role_id =b.id')
                    ->where(["user_id" => $result["id"], "status" => 1])
                    ->value("role_id");
                if ($result["id"] != 1 && (empty($groups) || empty($result['user_status']))) {
                    $this->error(lang('USER_DISABLED'));
                }
                //登入成功页面跳转
                session('ADMIN_ID', $result["id"]);
                session('name', $result["user_login"]);
                $data                    = [];
                $data['last_login_ip']   = get_client_ip(0, true);
                $data['last_login_time'] = time();
                $deviceType = $this->request->header('XX-Device-Type');
                if (!$deviceType){
                    $deviceType='android';
                }
                $token                   = cmf_generate_user_token($result["id"], $deviceType);
//                $token = cmf_generate_user_token($userId, $this->deviceType);
//                if (!empty($token)) {
//                    session('token', $token);
//                }
                UserModel::where('id', $result['id'])->update($data);
                cookie("admin_username", $name, 3600 * 24 * 30);

//                $this->success(lang('LOGIN_SUCCESS'), url("admin/Index/index"));
                $this->success("登录成功!", ['token' => $token, 'user' => $result]);
            } else {
                $this->error(lang('PASSWORD_NOT_RIGHT'));
            }
        } else {
            $this->error(lang('USERNAME_NOT_EXIST'));
        }
//        $user = Db::name('user')->where('id', $userId)->find();


//        var_dump($data);


        $this->success("登录成功!", ['token' => $token, 'user' => $user]);
    }
    /**
     * 新版本手机号登录
     */
    public function PhoneLogin(){
        $code = input('post.code', '');
        $iv = input('post.iv', '');
        $encryptedData = input('post.encryptedData', '');
        $user_id = input('post.user_id', '');
        if (!$code) {
            $this->ajaxReturn(['status' => -1, 'msg' => 'code值非空', 'result' => '']);
        }




        $miniapp = new MiniAppUtil();
        //新版接口:wx.getUserPhone, 小程序端需要传versionCode
        try {
            $session = array();
            $errCode = $miniapp->getPhoneNumber($code, $iv, $encryptedData, $session);
            $session = json_decode($session, true);
        }catch (Exception $e){

            $this->ajaxReturn('错误');
        }
        $user_id = $this->getUserId();


        if (empty($user_id)) {
            $this->ajaxReturn(['status' => -1, 'msg' => 'token失效', 'result' => '']);
        }
        $mobile = Db::name('user')->where('id', $user_id)->field('mobile')->find();
        if ($mobile['mobile'] == $session['phoneNumber']) {
            //重新获取用户信息，补全数据
            $data =Db::name('user')->where('id', $user_id)->find();
            $this->ajaxReturn($data);
//            $this->ajaxReturn(['status' => 1, 'msg' => '联系方式已更新', 'result' => $session['phoneNumber']]);
        }
        $res = Db::name('user')->where('id', $user_id)->update(['mobile' => $session['phoneNumber']]);
        if ($res) {

            //重新获取用户信息，补全数据
            $data =Db::name('user')->where('id', $user_id)->find();
            $this->ajaxReturn($data);
        } else {
            $this->ajaxReturn(['status' => -1, 'msg' => '更新失败', 'result' => '']);
        }
    }
    /**
     * 根据用户code判断是否在本系统建立账号
     * wudun 20210816
     */
    public function get_userInfo()
    {
//        include Env::get('root_path') . "public/plugins/Wechat/WxCommon.php";
        $code = input('post.code', '');
        $miniapp = new MiniAppUtil();
//        var_dump($code);
        $data = $miniapp->getSessionInfo($code);
        $data['device_type'] = input('post.device_type', 'wxapp');
        if ($data === false) {
//            "设置失败", '968888'
            $this->error("小程序登录失败",  $data);
//            throw new TpshopException("小程序登录失败", 0, ['status' => 0, 'msg' => $this->getError(), 'result' => '']);
        }
        $data['oauth'] = 'miniapp';
//        var_dump($data);
        $findThirdPartyUser = $miniapp->getThirdUser_new($data);
        if (empty($findThirdPartyUser)) {
            //账户不存在
            $this->error( '账户不存在');
        }
        $currentTime = time();
        $ip = $this->request->ip(0, true);
        if (empty($this->deviceType) && (empty($data['device_type']) || !in_array($data['device_type'], $this->allowedDeviceTypes))) {
            $this->error("请求错误,未知设备!");
        } else if (!empty($data['device_type'])) {
            $this->deviceType = $data['device_type'];
        }
        if ($findThirdPartyUser) {
            $userId = $findThirdPartyUser['user_id'];
            $token = cmf_generate_user_token($findThirdPartyUser['user_id'], $this->deviceType);

            $userData = [
                'last_login_ip' => $ip,
                'last_login_time' => $currentTime,
                'login_times' => Db::raw('login_times+1'),
                'more' => ''
            ];

            if (isset( $data['unionId'])) {
                $userData['union_id'] =$data['unionId'];
            }
            $wxPay= cmf_get_option('wxapp_settings');
            $config=$wxPay['default'];
            Db::name("third_party_user")
                ->where('openid',  $data['openid'])
                ->where('app_id',  $config['app_id'])
                ->update($userData);

        } else {

            //TODO 使用事务做用户注册
            $userId = Db::name("user")->insertGetId([
                'create_time' => $currentTime,
                'user_status' => 1,
                'user_type' => 2,
                'sex' => 2,
                'user_nickname' => $data->nickname,
                'avatar' => $data->figureurl_1,
                'last_login_ip' => $ip,
                'last_login_time' => $currentTime,
            ]);

            Db::name("third_party_user")->insert([
                'openid' => $data->openid,
                'user_id' => $userId,
                'third_party' => 'qq',
                'app_id' => $data->appid,
                'last_login_ip' => $ip,
                'union_id' => isset($data->unionId) ? $data->unionId : '',
                'last_login_time' => $currentTime,
                'create_time' => $currentTime,
                'login_times' => 1,
                'status' => 1,
                'more' => ''
            ]);

            $token = cmf_generate_user_token($userId, $this->deviceType);

        }

        $user = Db::name('user')->where('id', $userId)->find();
        $user['avatar'] = cmf_get_image_url($user['avatar']);
        $this->success("登录成功!", ['token' => $token, 'user' => $user]);
























//        $user=
//        $allowedDeviceTypes = $this->allowedDeviceTypes;
//
//        if (empty($this->deviceType) && (empty($data['device_type']) || !in_array($data['device_type'], $this->allowedDeviceTypes))) {
//            $this->error("请求错误,未知设备!");
//        } else if (!empty($data['device_type'])) {
//            $this->deviceType = $data['device_type'];
//        }
//
////        Db::name("user_token")
////            ->where('user_id', $findUser['id'])
////            ->where('device_type', $data['device_type']);
//        $findUserToken = Db::name("user_token")
//            ->where('user_id', $user['id'])
//            ->where('device_type', $this->deviceType)
//            ->find();
//        $currentTime = time();
//        $expireTime = $currentTime + 24 * 3600 * 180;
//        $token = md5(uniqid()) . md5(uniqid());
//        if (empty($findUserToken)) {
//            $result = Db::name("user_token")->insert([
//                'token' => $token,
//                'user_id' => $user['id'],
//                'expire_time' => $expireTime,
//                'create_time' => $currentTime,
//                'device_type' => $this->deviceType
//            ]);
//        } else {
//            $result = Db::name("user_token")
//                ->where('user_id', $user['id'])
//                ->where('device_type', $this->deviceType)
//                ->update([
//                    'token' => $token,
//                    'expire_time' => $expireTime,
//                    'create_time' => $currentTime
//                ]);
//        }
//
//
//        if (empty($result)) {
//            $this->error("登录失败!");
//        }
//        $user['token']=$token;
////        $findUser['avatar'] = cmf_get_image_url($user['avatar']);
//
//        $this->success('账户已存在',  $user);
    }
    /**
     * 首次授权后直接创建用户账户
     */
    public function createUser()
    {
//        var_dump(input());
//        exit();
//        $map['openid'] = input('openid', '');
//        $map['nickname'] = input('nickname', '');
//        $map['head_pic'] = input('head_pic', '');
//        $map['unionid'] = input('unionid', '');
//        $map['push_id'] = input('push_id', '');
//        $map['sex'] = input('sex', 0);
//        $map['oauth'] = input('oauth', '');
//        $map['versionCode'] = input('versionCode', '');
//        //小程序昵称过滤特殊字符
//        $map['nickname'] && $map['nickname'] = replaceSpecialStr($map['nickname']);
//
//        if ($map['oauth'] == 'miniapp') {
//
//            $code = input('post.code', '');
//            $iv = input('post.iv', '');
//            $signature = input('post.signature', '');
//            $encryptedData = input('post.encryptedData', '');
//            if (!$code) {
//                $this->ajaxReturn(['status' => -1, 'msg' => 'code值非空', 'result' => '']);
//            }
//            $miniapp = new MiniAppUtil();
//
//
//            //新版接口:wx.getUserInfo, 小程序端需要传versionCode
//            try {
////                $errCode = $miniapp->getWxUserInfo($code, $iv, $encryptedData, $session);
//                $session = $miniapp->getSessionInfo($code);
////                $session = json_decode($session, true);
//            } catch (TpshopException $t) {
//                $error = $t->getErrorArr();
//                $this->ajaxReturn($error);
//            }
//
//            $map['openid'] = $session['openid'] ? $session['openid'] : $session['openId'];
//            $map['unionid'] = $session['unionid'] ? $session['unionid'] : $session['unionId'];
//        }
////    创建账号
//        if (!$map['openid'] || !$map['oauth']) {
//            return array('status' => -1, 'msg' => '参数有误', 'result' => 'aaa');
//        }
//        $map['push_id'] && $map['push_id'] = $map['push_id'];
////        $map['token'] = md5(time() . mt_rand(1, 999999999));
//        $map['last_login'] = time();
//
//        $user = $this->userLogic->getThirdUser_new($map);
//
//        if (empty($user)) {
//            //账户不存在 注册一个
//            $insertdata['password'] = md5(123456);
////            $insertdata['openid'] = $map['openid'];
//            $insertdata['token'] = md5(time() . mt_rand(1, 999999999));
//            $insertdata['nickname'] = $map['nickname'];
//            $insertdata['reg_time'] = time();
//            $insertdata['oauth'] = $map['oauth'];
//            $insertdata['head_pic'] = !empty($map['head_pic']) ? $map['head_pic'] : '/public/images/icon_goods_thumb_empty_300.png';
//            $insertdata['sex'] = $map['sex'] === null ? 0 : $map['sex'];
////            $insertdata['first_leader'] = cookie('first_leader'); // 推荐人id
//            $insertdata['last_login'] = time();
//
//
//            // 成为分销商条件
//            //$distribut_condition = tpCache('distribut.condition');
//            //if($distribut_condition == 0)  // 直接成为分销商, 每个人都可以做分销
////        $map['is_distribut'] = 1;
//            $row_id = Db::name('users')->add($insertdata);
//            $updatedata['user_id'] = $row_id;
//            $updatedata['openid'] = $map['openid'];
//            $updatedata['unionid'] = $map['unionid'];
//            $updatedata['oauth'] = $map['oauth'];
//            Db::name('oauth_users')->insert($updatedata);//补充其他第三方登录方式
//
//            $this->ajaxReturn(['status' => 1, 'msg' => '创建成功', 'result' => $insertdata]);
//
//        } else {
//            //由用户更新数据
//
//            $this->ajaxReturn(['status' => 1, 'msg' => '有用户', 'result' => '']);
//        }
        $map['openid'] = input('openid', '');
        $map['nickname'] = input('nickname', '');
        $map['head_pic'] = input('head_pic', '');
        $map['unionid'] = input('unionid', '');
        $map['push_id'] = input('push_id', '');
        $map['sex'] = input('sex', 0);
        $map['oauth'] = input('oauth', '');
        $map['versionCode'] = input('versionCode', '');
        //小程序昵称过滤特殊字符
        $map['nickname'] && $map['nickname'] = replaceSpecialStr($map['nickname']);
        $code = input('post.code', '');
        $miniapp = new MiniAppUtil();
//        var_dump($code);
        $data = $miniapp->getSessionInfo($code);
//        var_dump($data);exit();
        $map['openid'] = $data['openid'] ? $data['openid'] : $data['openId'];
//            $map['unionid'] = $data['unionid'] ? $data['unionid'] : '';
        $map['device_type'] = input('post.device_type', 'wxapp');
        if ($data === false) {
//            "设置失败", '968888'
            $this->error("小程序登录失败",  $data);
//            throw new TpshopException("小程序登录失败", 0, ['status' => 0, 'msg' => $this->getError(), 'result' => '']);
        }
        $data['oauth'] = 'miniapp';
//        var_dump($data);
        $findThirdPartyUser = $miniapp->getThirdUser_new($data);
//        if (empty($findThirdPartyUser)) {
//            //账户不存在
//            $this->error( '账户不存在');
//        }
     ;
        $currentTime = time();
        $ip = $this->request->ip(0, true);
        if (empty($this->deviceType) && (empty($map['device_type']) || !in_array($map['device_type'], $this->allowedDeviceTypes))) {
            $this->error("请求错误,未知设备!");
        } else if (!empty($map['device_type'])) {
            $this->deviceType = $map['device_type'];
        }
        if ($findThirdPartyUser) {
            $userId = $findThirdPartyUser['user_id'];
            $token = cmf_generate_user_token($findThirdPartyUser['user_id'], $this->deviceType);

            $userData = [
                'last_login_ip' => $ip,
                'last_login_time' => $currentTime,
                'login_times' => Db::raw('login_times+1'),
                'more' => ''
            ];

            if (isset( $map['unionId'])) {
                $userData['union_id'] =$map['unionId'];
            }
            $wxPay= cmf_get_option('wxapp_settings');
            $config=$wxPay['default'];
            Db::name("third_party_user")
                ->where('openid',  $map['openid'])
                ->where('app_id',  $config['app_id'])
                ->update($userData);

        } else {

            //TODO 使用事务做用户注册
            $userId = Db::name("user")->insertGetId([
                'create_time' => $currentTime,
                'user_status' => 1,
                'user_type' => 2,
                'sex' => 2,
                'user_nickname' => $map['nickname'],
                'avatar' => $map['head_pic'],
                'last_login_ip' => $ip,
                'last_login_time' => $currentTime,
            ]);
            $wxPay= cmf_get_option('wxapp_settings');
            $config=$wxPay['default'];
            Db::name("third_party_user")->insert([
                'openid' => $map['openid'],
                'user_id' => $userId,
                'third_party' => 'wxapp',
                'app_id' =>$config['app_id'],
                'last_login_ip' => $ip,

                'last_login_time' => $currentTime,
                'create_time' => $currentTime,
                'login_times' => 1,
                'status' => 1,
                'more' => ''
            ]);

            $token = cmf_generate_user_token($userId, $this->deviceType);

        }

        $user = Db::name('user')->where('id', $userId)->find();
        $user['avatar'] = cmf_get_image_url($user['avatar']);
        $user['token'] = $token;
        $this->success("登录成功!", ['token' => $token, 'user' => $user]);
    }
    /**取消订单接口  用于没有付款的情况
     * @param $order_sn
     */
    function quxiao($order_sn){
        //判断是否是登录的用户调用的本接口
        $userid = $this->getUserId();

        if (!$order_sn){
            $this->error("参数为空");
        }

        $indexService = new IndexService();
        $order_obj_ = $indexService->get_order_obj($order_sn,$userid,'user_id');

        $result = '';
        $status     = $order_obj_['status'];
        $order_id   = $order_obj_['order_id'];
        $pay_status = $order_obj_['pay_status'];
        $total_fee = $order_obj_['real_amount'];
        $remark_msg = '您取消了订单(' . $order_sn . ')';

        if (!$order_obj_){
            $this->error("订单号有误");
        }
        if ($status > 2){
            $this->error("订单状态有误");
        }
        Db::startTrans(); //开启事务
        // try {

        $data_pay['pay_status'] = 2;
        $data_pay['status']     = 6;
        $update_ = $indexService->update_order_obj_array($order_id,$data_pay);
        // $update_ = $indexService->update_order_obj($order_id,'status',6);//更新订单状态
        //取消日志
        $msg_ret = create_user_message(1,$userid, '取消订单', $remark_msg, $remark_msg);

        if($status > 0){//是否已接单
            $up_cancle_ = $indexService->up_user_param($userid,'cancle_num',1);
            //司机消息推送
            $refund_ = $indexService->jpush_send_driver(2,'订单取消，单号(' . $order_sn . ')用户已取消',$order_obj_['driver_id']);
        }
        //消息推送
        $refund_ = $indexService->jpush_send_user(1,'您的订单(' . $order_sn . ')取消成功',$userid);

        if(!$update_ ){
            Db::rollback();
            $this->error("订单取消失败");
        }
        // 提交事务
        Db::commit();
        $this->success('订单取消成功', $result);
    }
    /**
     * @api {post} user_order 用户余额日志user_message_sys_detail
     * @apiGroup my
     *
     * @apiParam {String} token 参数说明.
     *
     * @apiSuccess {String} code 成功返回值.
     * @apiSuccess {String} msg  成功返回说明.
     * @apiSuccess {String} data  成功返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *      "code": 1,
     *      "msg": '获取成功'
     *      "data": ""
     *     }
     *
     * @apiError {String} code 错误返回值.
     * @apiSuccess {String} msg  错误返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": '',
     *      "msg": '获取失败'
     *     }
     */
    public function user_balance_log($page)
    {
        $user_id = $this->getUserId();
        $myservice = new MyService();
        $balance_list = $myservice->get_user_balance_log($user_id, $page);

        if (!count($balance_list)) {
            $this->error("已加载完成");
        }
        $this->success("获取成功!", $balance_list);

    }

    /**
     * @api {post} user_order 用户余额日志
     * @apiGroup my
     *
     * @apiParam {String} token 参数说明.
     *
     * @apiSuccess {String} code 成功返回值.
     * @apiSuccess {String} msg  成功返回说明.
     * @apiSuccess {String} data  成功返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *      "code": 1,
     *      "msg": '获取成功'
     *      "data": ""
     *     }
     *
     * @apiError {String} code 错误返回值.
     * @apiSuccess {String} msg  错误返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": '',
     *      "msg": '获取失败'
     *     }
     */
    public function user_balance()
    {
        $user_id = $this->getUserId();
        $myservice = new MyService();
        $balance_list = $myservice->user_balance($user_id);

        if (!$balance_list) {
            $this->error("已加载完成");
        }
        $this->success("获取成功!", $balance_list);

    }

    /**
     * @api {post} user_messgae 用户订单通知
     * @apiGroup my
     *
     * @apiParam {String} token 参数说明.
     *
     * @apiSuccess {String} code 成功返回值.
     * @apiSuccess {String} msg  成功返回说明.
     * @apiSuccess {String} data  成功返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *      "code": 1,
     *      "msg": '获取成功'
     *      "data": ""
     *     }
     *
     * @apiError {String} code 错误返回值.
     * @apiSuccess {String} msg  错误返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": '',
     *      "msg": '获取失败'
     *     }
     */
    public function user_messgae($page)
    {
        $user_id = $this->getUserId();
        $myservice = new MyService();
        $balance_list = $myservice->get_user_meaaage_log($user_id, $page,1);

        if (!$balance_list) {
            $this->error("已加载完成");
        }
        $this->success("获取成功!", $balance_list);

    }
	/**
	 * @api {post} user_messgae 用户系统通知
	 * @apiGroup my
	 *
	 * @apiParam {String} token 参数说明.
	 *
	 * @apiSuccess {String} code 成功返回值.
	 * @apiSuccess {String} msg  成功返回说明.
	 * @apiSuccess {String} data  成功返回数据.
	 *
	 * @apiSuccessExample Success-Response:
	 *     HTTP/1.1 200 OK
	 *     {
	 *      "code": 1,
	 *      "msg": '获取成功'
	 *      "data": ""
	 *     }
	 *
	 * @apiError {String} code 错误返回值.
	 * @apiSuccess {String} msg  错误返回说明.
	 *
	 * @apiErrorExample Error-Response:
	 *     HTTP/1.1 404 Not Found
	 *     {
	 *         "code": '',
	 *      "msg": '获取失败'
	 *     }
	 */
	public function user_messgae_sys($page,$utype)
	{
	    $user_id = $this->getUserId();
	    $myservice = new MyService();
	    $balance_list = $myservice->get_user_meaaage_sys_log($user_id, $page,$utype);

	    if (!count($balance_list['data'])) {
	        $this->error("已加载完成");
	    }
	    $this->success("获取成功!", $balance_list);

	}
	/**
	 * @api {post} user_message_de 用户订单消息详情
	 * @apiGroup my
	 *
	 * @apiParam {String} token 参数说明.
	 *
	 * @apiSuccess {String} code 成功返回值.
	 * @apiSuccess {String} msg  成功返回说明.
	 * @apiSuccess {String} data  成功返回数据.
	 *
	 * @apiSuccessExample Success-Response:
	 *     HTTP/1.1 200 OK
	 *     {
	 *      "code": 1,
	 *      "msg": '获取成功'
	 *      "data": ""
	 *     }
	 *
	 * @apiError {String} code 错误返回值.
	 * @apiSuccess {String} msg  错误返回说明.
	 *
	 * @apiErrorExample Error-Response:
	 *     HTTP/1.1 404 Not Found
	 *     {
	 *         "code": '',
	 *      "msg": '获取失败'
	 *     }
	 */
	public function user_message_sys_detail($message_id)
	{
	    $user_id = $this->getUserId();
	    $myservice = new MyService();
	    $balance_list = $myservice->get_user_meaaage_sys_detail($user_id, $message_id,1);

	    // if (!$balance_list) {
	    //     $this->error("已加载完成");
	    // }
	    $this->success("获取成功!", $balance_list);
	}
    /**
     * @api {post} user_message_de 用户订单消息详情
     * @apiGroup my
     *
     * @apiParam {String} token 参数说明.
     *
     * @apiSuccess {String} code 成功返回值.
     * @apiSuccess {String} msg  成功返回说明.
     * @apiSuccess {String} data  成功返回数据.
     *
     * @apiSuccessExample Success-Response:
     *     HTTP/1.1 200 OK
     *     {
     *      "code": 1,
     *      "msg": '获取成功'
     *      "data": ""
     *     }
     *
     * @apiError {String} code 错误返回值.
     * @apiSuccess {String} msg  错误返回说明.
     *
     * @apiErrorExample Error-Response:
     *     HTTP/1.1 404 Not Found
     *     {
     *         "code": '',
     *      "msg": '获取失败'
     *     }
     */
    public function user_message_de($id)
    {
        $user_id = $this->getUserId();
        $myservice = new MyService();
        $balance_list = $myservice->get_user_meaaage_detail($user_id, $id);

        if (!$balance_list) {
            $this->error("已加载完成");
        }
        $this->success("获取成功!", $balance_list);
    }


    /*
     * 极光推送demo   wudun
     */
    public function jpush_send()
    {
        $param = [
            'type' => 1,      //1是用户端 2是司机端
            'registration_id' => '1507bfd3f7b2a47a16a',       //用户设备推送id(也可以是多个组成的数组)
            'msg' => '测试推送消息内容'     //推送消息内容
        ];
        $res = hook_one('jpush_send', $param);
        if ($res['http_code'] == 200) {
            $this->success("推送成功!");
        } else {
            $this->error("推送失败");
        }
    }

    //微信退款demo    wudun
    public function create_refund()
    {
        $param = [
            'out_trade_no' => 'J201908101410100876',     //系统内部订单号
            'out_refund_no' => 'tk201908101169112433',       //内部的退款单号
            'total_fee' => 0.01,     //订单总金额
            'refund_fee' => 0.01    //退款总金额
        ];
        $res = hook_one('create_refund', $param);
        var_dump($res);
        exit;

    }

}
